package com.huonan.component.kafka;

import lombok.extern.slf4j.Slf4j;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.support.Acknowledgment;
import org.springframework.stereotype.Component;

import static com.huonan.component.kafka.KafkaProducer.TOPIC;

@Slf4j
@Component
public class KafkaConsumer {

    @KafkaListener(topics = TOPIC,id = "test_ms_id",groupId = "test_g_ms_id",clientIdPrefix="test",
            concurrency="3",containerFactory = "batchFactory")
    public void consumeMessage(String message,Acknowledgment ack) {
        // 处理接收到的消息
        log.info(message);
        try {
            ack.acknowledge();
        } catch (Exception e) {
            ack.nack(0,1000);
            throw new RuntimeException(e);
        }
    }
}